package com.xiaoxu.rental.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.xiaoxu.rental.entity.RentalType;
import com.xiaoxu.rental.service.RentalTypeService;
import com.xiaoxu.rental.util.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

/**
 * @Title: RentalTypeController
 * @Author Mr.Xu
 * @Package com.xiaoxu.rental.controller
 * @Date 2024/7/31 12:55
 * @description:
 */
@Api(tags = "租赁类型管理")
@RestController
@RequestMapping("/rental/rentalType")
@SuppressWarnings("all")
public class RentalTypeController {

    @Resource
    private RentalTypeService rentalTypeService;

    @ApiOperation(value = "分页查询")
    @PostMapping("{start}/{size}")
    public Result search(@PathVariable int start, @PathVariable int size,
                         @RequestBody RentalType rentalType){
        Page<RentalType> page=new Page<>(start,size);
        return
                Result.success(rentalTypeService.searchByPage(page,rentalType));
    }

    @ApiOperation(value = "新增")
    @PostMapping
    public Result save(@RequestBody RentalType rentalType){
        return rentalTypeService.save(rentalType)?
                Result.success():Result.fail();
    }
    @PutMapping
    public Result update(@RequestBody RentalType rentalType){
        return rentalTypeService.updateById(rentalType)?
                Result.success():Result.fail();
    }
    @DeleteMapping("/{ids}")
    public Result delete(@PathVariable String ids){
        return rentalTypeService.delete(ids)?Result.success():Result.fail();
    }
    @GetMapping
    public Result selectAll(){
        return Result.success(rentalTypeService.list());
    }
}
